<body>
	<div class="container minh">
		<ol class="breadcrumb">
			<li class="breadcrumb-item">评论管理</li>
			<li class="breadcrumb-item active">评论列表</li>
		</ol>
		<div class="card mb-3">
			<div class="table-responsive">
				<table id="comment" class="table table-striped table-bordered" style="width: 100%;">
					<thead>
						<tr>
							<th>序号</th>
							<th>内容编号</th>
							<th>评论账号</th>
							<th>评论内容</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>更新时间</th>
							<th>操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {
			var url = "vendor/datatables/zh_CN.json";
			$('#comment').dataTable({
				"language" : {
					url : url
				},
				"ajax" : 'console/comments.json',
				"processing" : true,
				"serverSide" : true,
				"ordering": false,
				"dataSrc" : "",
				"columns" : [ {
					"data" : "id"
				}, {
					"data" : "contentId"
				}, {
					"data" : "cname"
				}, {
					"data" : "comment"
				}, {
					"data" : "status",
					"render" : function(data, type, row, meta) {
						if(data=="VALID"){
							 data ="有效";
						}else{
							 data ="无效";
						}
					return	 data;
					}
				}, {
					"data" : "createTime",
					"render" : function(data, type, row, meta) {
						//时间格式化
						return  moment(data).format("YYYY-MM-DD HH:mm:ss");
					}
				}, {
					"data" : "updateTime",
					"render" : function(data, type, row, meta) {
						//时间格式化
						return  moment(data).format("YYYY-MM-DD HH:mm:ss");
					}
				},{
					"data" : "id",
				    "render":function(data, type, row, meta){
					    return	data='<button id="deleteOne" class="btn btn-danger btn-sm" data-id='+data+'>删 除</button>';				    	
					    }	
				} ]
			});
		});
		
		/**
		 * 单行删除按钮点击事件响应
		 */
		$(document).delegate('#deleteOne', 'click', function() {
			$("#deleteOneSubmit").val($(this).data("id"));
			$("#deleteOneModal").modal('show');
		});

		/**
		 * 点击确认删除按钮
		 */
		$(document).delegate('#deleteOneSubmit', 'click', function() {
			$('#deleteOneModal').modal('hide');
			$.ajax({
				url : "console/deleteComment/" + $(this).val(),
				async : true,
				type : "POST",
				dataType : "json",
				cache : false, 
				success : function(data) {
					if (data.resultCode == "SUCCESS") {
						$('#comment').DataTable().ajax.reload(); 
					} else {
						alert("删除失败");
					}
				},
				error : function(data) {
					alert("请求异常");
				}
			});
		});
		
	</script>

	<div class="modal fade" id="deleteOneModal">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-header">
					<h6 class="modal-title">删除确认</h6>
					<button type="button" class="close" data-dismiss="modal">&times;</button>
				</div>
				<div class="modal-body">您确定要删除当前评论吗？</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" id="deleteOneSubmit">确认</button>
				</div>
			</div>
		</div>
	</div>
	
</body>